#ifndef blob_detect
#define blob_detect

#include "highgui.h"
#include "cv.h"
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <cxcore.h>

using namespace std;
using namespace cv;

#define WHITE 255;
#define BLACK 0;

#define UPPERRIGHT 4;
#define UPPERLEFT 8;
#define LOWERLEFT 2;
#define LOWERRIGHT 1;

#define PREVUP 8;
#define PREVDOWN 4;
#define PREVLEFT 2;
#define PREVRIGHT 1;

struct HSV{
	int HLower;
	int SLower;
	int VLower;
	int HUpper;
	int SUpper;
	int VUpper;
};


class BlobDetector{

public:

	int  MassRowL, MassColL, LastTransX, LastTransY, LastMassRow, LastMassCol, XCentre, YCentre;
	HSV Red;
	HSV Blue;
	HSV Yellow;
	HSV Green;

	BlobDetector()
		:LastMassCol(0),
		LastMassRow(0)
	{
		Red.HLower = 175;
		Red.SLower = 200;
		Red.VLower = 170;
		Red.HUpper = 179;
		Red.SUpper = 255;
		Red.VUpper = 255;
		Blue.HLower = 85;
		Blue.SLower = 100;
		Blue.VLower = 100;
		Blue.HUpper = 130;
		Blue.SUpper = 255;
		Blue.VUpper = 255;
		Yellow.HLower = 24;
		Yellow.SLower = 200;
		Yellow.VLower = 200;
		Yellow.HUpper = 32;
		Yellow.SUpper = 255;
		Yellow.VUpper = 255;
		Green.HLower = 35;
		Green.SLower = 100;
		Green.VLower = 100;
		Green.HUpper = 80;
		Green.SUpper = 255;
		Green.VUpper = 255;

	};

	Mat Frame, ImgHSV, Scratch, WorkImage, GrayscaleImage, BinaryImage, Image, QTImage, ImageStore;
	VideoCapture Cam;

	void loadImage(const string& filename);
	void LoadLiveFeed(VideoCapture Cam, int TargetColor);

	void Crosshair(VideoCapture Cam);

	void blank();

	void MoveUp();
	void MoveDown();
	void MoveLeft();
	void MoveRight();

	void BackgroundBorder();
	void BackgroundBorder(Mat Image);

	int Image_Scan();
	int Image_Scan(Mat WorkImage);

	void Follow_Contour();
	void Follow_contour(Mat WorkImage);
	void Follow_contour(Mat WorkImage, bool DrawContour);

private:
	int x, y, Ycor, Xcor, AreaRow, AreaCol, MinRow, MinCol, MaxRow, MaxCol, Area, AreaL, MassRow, MassCol;
	int Row, Col, SumRow, SumCol;

	uchar PrevPixel, PrevMove;
	Vec3b pixelElement;
};



#endif
